{php echo Common::getCss('price_set.css'); }
{php echo Common::getCss('calendar-price-jquery.min.css'); }
<div class="stock-offer-block">
    {if $channel['supplier']}
    <ul class="info-item-block">
        <li>
            <span class="item-hd">结算方式：</span>
            <div class="item-bd">
                <label class="radio-label mr-10">
                    <input name="settlement_type" {if $settlement_type==1 || !$settlement_type}checked="checked"{/if} type="radio" value="1">结算价
                </label>
                <label class="radio-label">
                    <input name="settlement_type" {if $settlement_type==2}checked="checked"{/if} type="radio" value="2">销售价
                </label>
            </div>
        </li>
    </ul>
    {/if}
    <div class="stock-offer-tabnav">
        <span class="tabnav-item number-set selected filled"><i>1</i>库存管理</span>
        <span class="tabnav-item price-set "><i>2</i>日历报价</span>
    </div>
</div>
<ul class="info-item-block">
    <li class="number-container">
        <span class="item-hd">库存：</span>
        <div class="item-bd">
            <button type="button" class="fl btn btn-primary radius size-S mt-3 mr-5" id="number_set_btn">设置库存</button>
            <a type="button" class="fl btn btn-primary radius size-S mt-3 mr-5" onclick="clearNumber()">清除库存</a>
        </div>
    </li>
    <li class="number-container">
        <span class="item-hd"></span>
        <div class="item-bd">
            <div class="number_container fl">

            </div>
        </div>
    </li>
</ul>
<ul class="info-item-block price-container" style="display: none">
    {if $type_id<200}
    <li>
        <span class="item-hd">渠道{Common::get_help_icon('product_suit_price')}：</span>
        <div class="item-bd">
            {loop $channel['channel'] $k $c}
            <label class="radio-label mr-10"><input type="radio" name="channel_id" {if $k<1}checked="checked"{/if} value="{$c['id']}">{$c['title']}</label>
            {/loop}
        </div>
    </li>
    {/if}
    <li>
        <span class="item-hd">报价{Common::get_help_icon('product_suit_price')}：</span>
        <div class="item-bd">
            <a href="javascript:;" class="fl btn btn-primary radius size-S mt-3 mr-5" onclick="add_suit_price()" title="添加报价">添加报价</a>
            <a href="javascript:;" class="btn btn-grey-outline radius size-S mt-3 ml-5" onclick="delall()">清除报价</a>
        </div>
    </li>
    <li>
        <span class="item-hd"></span>
        <div class="item-bd">
            <div class="container fl">

            </div>
        </div>
    </li>
</ul>
<!--设置库存在这个里面supplier_set_product-->
{php echo Common::getScript("supplier_set_product.js,calendar_new/calendar-price-jquery.js"); }
<script>
    var type_id = "{$type_id}";
    var web_host = "{$web_host}";
    var calendar_config = '{$calendar_config}';
    calendar_config = JSON.parse(calendar_config);
    var adult_name = "{$people_group[2]['name']}";
    var child_name = "{$people_group[1]['name']}";
    var old_name = "{$people_group[3]['name']}";
    var pro4_name = "{$people_group[4]['name']}";
    var pro5_name = "{$people_group[5]['name']}";
    var pro6_name = "{$people_group[6]['name']}";
    var back_symbol = "{Currency_Tool::symbol()}";
    $(function(){
        ajax_get_calendar_number('',true);
        ajax_get_suit_price('', '', true);
        $("[name='channel_id']").on('click',function(){
            ajax_get_suit_price('', '', true);
        });
    })
    //按月加载数据
    function ajax_get_suit_price(y, m, init) {
        var suit_id = $(".public_suit_id").val();
        var channel_id = $("[name='channel_id']:checked").val();
        var out = [];
        $.ajax({
            type: 'post',
            dataType: 'json',
            async: false,
            data: {year:y, month:m, suit_id:suit_id, type_id:type_id, channel_id:channel_id},
            url: web_host + '/ajax_get_suit_price',
            success: function (data) {
                if (init) {
                    if (data.starttime) {
                        $('#more_price').show();
                        if(data.list.length>0){
                            $('.price-set').addClass('filled');
                        }
                        calendar_init(data)
                        $('.container').show();
                    } else {
                        $('#more_price').hide();
                        $('.container').hide();
                    }
                } else {
                    out = data.list;
                }
            }

        });

        return out;
    }

    //日历初始化
    function calendar_init(mockData) {
        $.CalendarPrice({
            // 显示日历的容器
            el: '.container',
            // 设置开始日期
            // 可选参数，默认为系统当前日期
            startDate: mockData.starttime,
            // 可选参数，默认为开始日期相同的1年后的日期
            // 设置日历显示结束日期
            //  endDate: '2018-09',
            // 初始数据
            data: mockData.list,
            //点击单个日期,修改报价
            everyday: function (data) {
                edit_price(data);
            },
            // 配置需要设置的字段名称，请与你传入的数据对象对应
            config: calendar_config,
            // 配置在日历中要显示的字段
            show: calendar_config,
            // 自定义风格(颜色)
            style: {
                // 详见参数说明
                // ...
                // 头部背景色
                //headerBgColor: '#f00',
                // 头部文字颜色
                //headerTextColor: '#fff'
            }
        });
    }

    //修改报价
    function edit_price(data) {
        var suit_id = $(".public_suit_id").val();
        var channel_id = $("[name='channel_id']:checked").val();
        var settlement_type = $("[name='settlement_type']:checked").val();
        settlement_type = settlement_type?settlement_type:1;
        CHOOSE.setSome("修改报价(" + data.date + ')', {
            maxHeight: 500,
            width: 700,
            loadWindow: window,
            loadCallback: calendar_edit
        }, web_host+'/dialog_edit_all_suit_price?suit_id='+suit_id+'&date='+data.date+'&type_id='+type_id+'&channel_id='+channel_id+'&settlement_type='+settlement_type,1)
    }

    //修改报价，更新日历
    function calendar_edit(data, bool) {
        if (!bool) {
            return false;
        } else {
            if(type_id==1){
                set_line_calendat_day_params(data)
            }else if(type_id==114){
                set_outdoor_calendat_day_params(data)
            }else{
                set_calendat_day_params(data);
            }
        }
    }
    //修改户外日历某天的显示数据
    function set_outdoor_calendat_day_params(data)
    {
        if(data.msg=='单日删除成功'){
            $('.calendar-table-wrapper td[data-id='+data.date+'] .data-hook').html('')
            return false
        }
        if(data['price']>0 || data['childprice']>0)
        {
            var html = '<p class="item"><span class="attr">成人价</span><span class="num">' + data.price + '</span></p>';
            html += '<p class="item"><span class="attr">儿童价</span><span class="num">' + data.childprice + '</span></p>';
            html+='<p class="item"><span class="attr">余位</span><span class="num">'+data.number+'</span></p>';
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html(html)
        }
        else
        {
            $('.calendar-table-wrapper td[data-id='+data.date+'] .data-hook').html('')
        }
    }

    //修改日历某天的显示数据
    function set_calendat_day_params(data)
    {
        if(data.msg=='单日删除成功'){
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html('')
            return false
        }
        if (data && data.price) {
            var price = '';
            var number = 0;
            data.number == -1 ? number = '充足' : number = data.number;
            price = back_symbol + data.price;
            var html = '<p class="item"><span class="attr">价格</span><span class="num">' + price + '</span></p>' +
                '<p class="item"><span class="attr">库存</span><span class="num">' + number + '</span></p>';
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html(html)
        }
        else {
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html('')
        }
    }

    //修改线路日历某天的显示数据
    function set_line_calendat_day_params(data)
    {
        if(data.msg=='单日删除成功'){
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html('')
            return false
        }
        var propgroup = JSON.parse(data.propgroup);
        if (propgroup[0]) {
            var adultprice = '';
            var childprice = '';
            var oldprice = '';
            var number = 0;
            data.number == -1 ? number = '充足' : number = data.number;
            var html = '';
            if ($.inArray('2', propgroup) != -1) {
                adultprice = back_symbol + data.adultprice;
                html += '<p class="item"><span class="attr">{$people_group[2]['name']}</span><span class="num">' + adultprice + '</span></p>';
            }
            if ($.inArray('1', propgroup) != -1) {
                childprice = back_symbol + data.childprice;
                html += '<p class="item"><span class="attr">{$people_group[1]['name']}</span><span class="num">' + childprice + '</span></p>';
            }
            if ($.inArray('3', propgroup) != -1) {
                oldprice = back_symbol + data.oldprice;
                html += '<p class="item"><span class="attr">{$people_group[3]['name']}</span><span class="num">' + oldprice + '</span></p>';
            }

            if ($.inArray('4', propgroup) != -1) {
                var price = back_symbol + data.people4_price;
                html += '<p class="item"><span class="attr">{$people_group[4]['name']}</span><span class="num">' + price + '</span></p>';
            }

            if ($.inArray('5', propgroup) != -1) {
                var price = back_symbol + data.people5_price;
                html += '<p class="item"><span class="attr">{$people_group[5]['name']}</span><span class="num">' + price + '</span></p>';
            }

            if ($.inArray('6', propgroup) != -1) {
                var price = back_symbol + data.people6_price;
                html += '<p class="item"><span class="attr">{$people_group[6]['name']}</span><span class="num">' + price + '</span></p>';
            }
            html += '<p class="item"><span class="attr">单房差</span><span class="num">' + back_symbol + data.roombalance + '</span></p>';
            html += '<p class="item"><span class="attr">限购</span><span class="num">' + number + '</span></p>';
            console.log(html);
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html(html)
        } else {
            $('.calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html('')
        }
    }

    //清除所有的报价
    function delall() {
        var suit_id = $(".public_suit_id").val();
        var channel_id = $("[name='channel_id']:checked").val();
        ST.Util.confirmBox('提示', '清除报价后，不可恢复。确定清空全部报价?', function () {
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {suit_id: suit_id, type_id: type_id, channel_id:channel_id},
                url: web_host+'/ajax_delete_price',
                success: function (data) {
                    ST.Util.showMsg('清除成功', 4, 1000);
                    ajax_get_suit_price('', '', true)
                }
            })
        })
    }

    //添加报价
    function add_suit_price() {
        var suit_id = $(".public_suit_id").val();
        var channel_id = $("[name='channel_id']:checked").val();
        var settlement_type = $("[name='settlement_type']:checked").val();
        settlement_type = settlement_type?settlement_type:1;
        if (!suit_id) {
            ST.Util.showMsg('请输入套餐名称', 5, 1000);
            return false;
        }
        CHOOSE.setSome("添加报价", {
            maxHeight: 600,
            width: 700,
            loadWindow: window,
            loadCallback: add_suit_price_callback
        }, web_host + '/dialog_edit_all_suit_price?suit_id='+suit_id+'&type_id='+type_id+'&channel_id='+channel_id+'&settlement_type='+settlement_type, 1)
    }

    //添加报价回调
    function add_suit_price_callback(result, bool) {
        if (!bool) {
            return false;
        }
        ajax_get_suit_price('', '', true)
    }

    //日期处理回调
    function calendarCallback(date) {
        return ajax_get_suit_price(date.getFullYear(), date.getMonth() + 1, false)
    }




</script>
